package com.example.houtai.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.houtai.entity.SysRegion;
import com.example.houtai.mapper.EsMapper;
import com.example.houtai.service.ISysRegionService;
import com.org.dto.IdNamePair;
import com.org.dto.SysRegionDto;
import com.org.vo.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 地区表 前端控制器
 * </p>
 *
 * @author 龚梦
 * @since 2021-03-22
 */
@RestController
@RequestMapping("/sys/region")
public class SysRegionController {


    @Autowired
    private ISysRegionService regionService;

    @Autowired
    private EsMapper esMapper;




    @RequestMapping("getArea")
    public ResultEntity getArea(Integer pid){
        QueryWrapper<SysRegion> wrapper = new QueryWrapper<>();
        wrapper.eq("PARENT_ID",pid);
        List<SysRegion> list = regionService.list(wrapper);
        return ResultEntity.ok(list);
    }





    @RequestMapping("selectregion")
    public ResultEntity selectregion(){
        List<SysRegionDto> citylist=regionService.selectregion();
        for (SysRegionDto sysRegionDto : citylist) {
            System.out.println(sysRegionDto);
        }
        return ResultEntity.ok("200",citylist);
    }


    @RequestMapping("handleBussinessCircleByRegionId")
    public ResultEntity handleBussinessCircleByRegionId(@RequestBody Map<String,Integer> map){
        Integer did = map.get("did");
        List<IdNamePair> idNamePairs = esMapper.businessCircleList(did);
        return ResultEntity.ok(idNamePairs);
    }


    @RequestMapping("getArea1")
    public ResultEntity getArea1(Integer pid){
        QueryWrapper<SysRegion> wrapper = new QueryWrapper<>();
        wrapper.eq("PARENT_ID",pid);
        List<SysRegion> list = regionService.list(wrapper);
        return ResultEntity.ok(list);
    }

    @RequestMapping("/byparentid")
    public ResultEntity byParentid(Integer id) {
        List<SysRegion> sysRegions = regionService.getByparent(id);
        return ResultEntity.ok("200", "查询成功", sysRegions);
    }
}
